package com.example.jobback.req.manager.employee;

import com.example.jobback.common.enums.ManagerType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @ClassName: ManagerEmployeeCreatedReq
 * @Description:管理员新增员工请求体请求体
 * @Author: lhb
 * @Date: 2025/6/30
 */
@Data
@Schema(title = "管理员新增员工请求体请求体")
public class ManagerEmployeeCreatedReq {

    @Schema(title = "增设员工的方式，0-已经在其他端注册过,不用传入密码，1-新建账号，需要输入密码")
    @NotNull(message="增设员工的方式不为空")
    //不设置枚举，图方便
    private Integer employeeCreatedSelect;

    @Schema(title = "电话号码")
    @NotBlank(message="电话号码不为空")
    private String phone;

    @Schema(title = "密码")
    private String password;

    @Schema(title = "要增设的管理员类别")
    @NotNull(message="类别不为空")
    private ManagerType type;

    @AssertTrue(message = "没注册过需要选择密码")
    @Schema(title = "校验逻辑，前端不用传递，不用管")
    public boolean isPasswordValid() {
        boolean hasPassword = StringUtils.isNotBlank(password);
        //新建
        if(Objects.equals(employeeCreatedSelect, 1) && BooleanUtils.isFalse(hasPassword)) {
            System.out.println(111);
            return false;
        }
        return true;
    }
}
